package ch.nortgram.countdown_worldcup_2014.fragment;

import java.io.IOException;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import ch.nortgram.countdown_worldcup_2014.R;
import ch.nortgram.countdown_worldcup_2014.util.DataLoader;

public class AboutFragment extends Fragment
	{

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved)
		{
		return inflater.inflate(R.layout.activity_about, group, false);
		}

	@Override
	public void onActivityCreated(Bundle savedInstanceState)
		{
		super.onActivityCreated(savedInstanceState);
		WebView creditsWebView = (WebView) getActivity().findViewById(R.id.about_thirdsparty_credits);
		try
			{
			creditsWebView.loadData(DataLoader.loadData(getActivity().getBaseContext(), "credits_thirdparty"), "text/html","UTF-8");
			}
		catch (IOException ioe)
			{
			}
		
		((ImageView)getActivity().findViewById(R.id.about_socialmedia_googlecode)).setOnClickListener(new OnClickListener()
			{
			@Override
			public void onClick(View v)
				{
				openBrowser(getActivity().getString(R.string.about_googlecode));
				}
			});
		((ImageView)getActivity().findViewById(R.id.about_socialmedia_googleplus)).setOnClickListener(new OnClickListener()
			{
			@Override
			public void onClick(View v)
				{
				openBrowser(getActivity().getString(R.string.about_googleplus));
				}
			});
		((ImageView)getActivity().findViewById(R.id.about_socialmedia_twitter)).setOnClickListener(new OnClickListener()
			{
			@Override
			public void onClick(View v)
				{
				openBrowser(getActivity().getString(R.string.about_twitter));
				}
			});
		((RelativeLayout)getActivity().findViewById(R.id.feedback_button)).setOnClickListener(new OnClickListener()
			{
			@Override
			public void onClick(View v)
				{
				((FragmentChangeActivity) getActivity()).switchContent(new RequestFragment());
				Log.e("","feedbackbutton");
				}
			});
		}
	
	private void openBrowser(String url) 
		{
		startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url)));
		}
	}